<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml"
      xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>公司管理</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link rel="stylesheet" href="/dist/plugins/select2/select2.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=39cd89cd">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style>
        .table > tbody > tr > td {
            height: 35px;
            max-height: 44px;
            overflow: hidden;
        }

        .selectBox .item .boxCenter {
            float: left;
            margin-left: 50px;
        }

        .selectBox .item .boxCenter a {
            margin-right: 20px;
        }
        label{
            font-size: 14px;
        }
    </style>
</head>
<body>
<section class="content" id="app" style="min-height: 0px;">
    <div class="box-body" style="overflow: auto;">
        <div class="boxCenter">
            <div v-for="(item,i) in brandList" style="width: 106px;height: 24px;float: left;">
                <label >
                    <input type="checkbox" style=" margin-left: 35px;width: 15px;height: 15px;
" :checked="checkedBrandLists.indexOf(item.brandName)>=0" value="item.brandName" @click="checkedOne(item.brandName,item.id)"/>{{item.brandName}}
                </label>
            </div>

        </div>
            <input type="button" value="保存" class="btn btn-primary btn-sm" @click="update()" style="margin-left: 33%;margin-top: 25px;"/>
    </div>
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=7e54a132"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=558d0414"></script>

<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script src="/dist/plugins/select2/select2.full.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript">
    var api = frameElement.api, W = api.opener;

    function refresh() {
        $.wyui.page.getByPage();
    }

    var app = new Vue({
        el: '#app',
        data: {
            checkedBrandLists: [],
            checkedBrandIds:[],
            brandList: [],
            company: {
                id: $.wyui.page.urlParams.id,
                name: '',
                delFlag: '0',
                createUserId: '',
                parentCompanyName: '',
                parentId: '',
                updateUserId: '',
                allName: '',
                fixedTelephone: '',
                provincialCapital: '',
                taxId: '',
                address: '',
                availableBrands: ''
            },
            deviceId:'',
            deviceName:'',
        },

        methods: {
            checkedOne: function (moduleKey,moduleId) {
                var idIndex = this.checkedBrandLists.indexOf(moduleKey)
                var checkedBrandIds=this.checkedBrandIds.indexOf(moduleId)
                if (idIndex >= 0) {
                    this.checkedBrandLists.splice(idIndex, 1)
                } else {
                    this.checkedBrandLists.push(moduleKey)
                }
                if (checkedBrandIds >= 0) {
                    this.checkedBrandIds.splice(checkedBrandIds, 1)
                } else {
                    this.checkedBrandIds.push(moduleId)
                }
                console.log(this.checkedBrandLists);
                console.log(this.checkedBrandIds);
            },
            update: function () {
                var that = this;
                var that = this;
                var checkedBrandLists = "";
                for (var i = 0; i < that.checkedBrandLists.length; i++) {
                    if (that.checkedBrandLists[i]!=""){
                        checkedBrandLists += that.checkedBrandLists[i] + ",";
                    }
                }
                var checkedBrandIds = "";
                for (var i = 0; i < that.checkedBrandIds.length; i++) {
                    if (that.checkedBrandIds[i]!=""){
                        checkedBrandIds += that.checkedBrandIds[i] + ",";
                    }
                }
                that.company.availableBrands = checkedBrandLists.substring(0, checkedBrandLists.length - 1);
                that.deviceId=checkedBrandIds.substring(0, checkedBrandIds.length - 1);
                $.wyui.postMethod('/company/updateDevice.json', {
                    id: that.company.id,
                    updateUserId: getCurrentUser().id,
                    parentId:that.company.parentId,
                    availableBrands: that.company.availableBrands,
                    deviceId:that.deviceId
                }, function (r) {
                    that.company = r
                    if (r.isOk) {
                        alert("修改成功")
                        var $iframe = top.findIframeByName("公司管理");
                        $iframe[0].contentWindow.refresh();
                        api.close();
                    } else {
                        alert("修改失败")
                    }

                });
            }
        },
        mounted: function () {
            var that = this;
            $.wyui.postMethod('/deviceBrand/getBrandList.json', {}, function (r) {
                that.brandList = r.records;
            });
            $.wyui.postMethod('/company/getCompanyById.json', {id: $.wyui.page.urlParams.id}, function (r) {
                that.company = r.company;

            });
            $.wyui.postMethod('/device/getDeviceByCompanyId.json', {companyId: $.wyui.page.urlParams.id}, function (r) {
                    var brandListsName="";
                    var brandListsId="";
                    console.log(r)
                     for (var i=0;i<r.length;i++) {
                         if (r[i].brandName){
                             brandListsName +=r[i].brandName+",";
                             brandListsId +=r[i].brandId+",";
                         }
                     }
                console.log(brandListsName);
                     if(brandListsName!=""){
                         that.checkedBrandLists = brandListsName.split(",");
                         that.checkedBrandIds=brandListsId.split(",")
                     }
                    console.log(that.checkedBrandLists)
                console.log(that.checkedBrandIds)


            });
        }
    });

</script>
</body>
</html>